package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TPrivilegeVerification;
import com.ruoyi.system.service.ITPrivilegeVerificationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 特权免押Controller
 * 
 * @author xiuddooo
 * @date 2025-10-10
 */
@RestController
@RequestMapping("/system/privilegeverification")
public class TPrivilegeVerificationController extends BaseController {
    @Autowired
    private ITPrivilegeVerificationService tPrivilegeVerificationService;

    /**
     * 查询特权免押列表
     */
    @PreAuthorize("@ss.hasPermi('system:privilegeverification:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPrivilegeVerification tPrivilegeVerification) {
        startPage();
        List<TPrivilegeVerification> list = tPrivilegeVerificationService.selectTPrivilegeVerificationList(tPrivilegeVerification);
        return getDataTable(list);
    }

    /**
     * 导出特权免押列表
     */
    @PreAuthorize("@ss.hasPermi('system:privilegeverification:export')")
    @Log(title = "特权免押", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPrivilegeVerification tPrivilegeVerification) {
        List<TPrivilegeVerification> list = tPrivilegeVerificationService.selectTPrivilegeVerificationList(tPrivilegeVerification);
        ExcelUtil<TPrivilegeVerification> util = new ExcelUtil<TPrivilegeVerification>(TPrivilegeVerification.class);
        util.exportExcel(response, list, "特权免押数据");
    }

    /**
     * 获取特权免押详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:privilegeverification:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tPrivilegeVerificationService.selectTPrivilegeVerificationById(id));
    }

    /**
     * 新增特权免押
     */
    @PreAuthorize("@ss.hasPermi('system:privilegeverification:add')")
    @Log(title = "特权免押", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPrivilegeVerification tPrivilegeVerification) {
        return toAjax(tPrivilegeVerificationService.insertTPrivilegeVerification(tPrivilegeVerification));
    }

    /**
     * 修改特权免押
     */
    @PreAuthorize("@ss.hasPermi('system:privilegeverification:edit')")
    @Log(title = "特权免押", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPrivilegeVerification tPrivilegeVerification) {
        return toAjax(tPrivilegeVerificationService.updateTPrivilegeVerification(tPrivilegeVerification));
    }

    /**
     * 删除特权免押
     */
    @PreAuthorize("@ss.hasPermi('system:privilegeverification:remove')")
    @Log(title = "特权免押", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tPrivilegeVerificationService.deleteTPrivilegeVerificationByIds(ids));
    }

    /**
     * 获取报告
     */
    @PreAuthorize("@ss.hasPermi('system:privilegeverification:edit')")
    @Log(title = "特权免押", businessType = BusinessType.UPDATE)
    @GetMapping("/report/{id}")
    public AjaxResult getReport(@PathVariable String id) {
        try {
            String result = tPrivilegeVerificationService.reportTPrivilegeVerificationById(id);
            return AjaxResult.success("操作成功", result);
        } catch (Exception e) {
            logger.error("调用接口出差错,",e);
            return AjaxResult.error(e.getMessage());
        }
    }
}
